package com.wmh.baseservice.operationaid.controller;

import com.alibaba.fastjson2.JSON;
import com.wmh.baseservice.common.utils.returnbody.ReturnBody;
import com.wmh.baseservice.operationaid.pojo.vo.keyWord.KeyWordTableReqVO;
import com.wmh.baseservice.operationaid.service.KeyWordService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.List;

import static com.wmh.baseservice.common.utils.returnbody.ReturnBody.success;

/**
 * @author dongaolong
 * @createDate 2023-05-29
 */
@Validated
@RestController
@RequestMapping("operationAid/KeyWord")
@Api(tags = "运营助手-关键词")
@Slf4j
public class KeyWordController {

    @Resource
    private KeyWordService keyWordService;

    @Resource
    private HttpServletRequest request;

    @ApiOperation("删除")
    @PostMapping("/delete")
    public String delete(String id) {
        List<Long> idList = JSON.parseArray(id, Long.class);
        boolean isSuccess = keyWordService.removeByIds(idList);
        if (!isSuccess) {
            return ReturnBody.error("删除失败,请检查后再次操作");
        }
        return success();
    }

    @ApiOperation("获取表格显示数据")
    @PostMapping("/table")
    public String getTable(KeyWordTableReqVO reqVO) {
        return success(keyWordService.getTable(reqVO));
    }

    @ApiOperation("获取数据周期列表")
    @PostMapping("/cycleList")
    public String getCycleList(String categoryName) {
        return success(keyWordService.getCycleList(categoryName));
    }

    @ApiOperation("获取创建时间列表")
    @PostMapping("/createTimeList")
    public String getCreateTimeList() {
        return success(keyWordService.getCreateTimeList());
    }

    @ApiOperation("获取品类名称")
    @PostMapping("/categoryNameList")
    public String getCategoryNameList(String cycle) {
        return success(keyWordService.getCategoryNameList(cycle));
    }
}